<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top:5%;height: 85%;overflow-y: hidden">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="团队角色">
          <a-input  placeholder="请输入团队角色"  v-decorator="[ 'teamRolename', validatorRules.teamRolename]"  />
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import {addTeamrole,duplicateCheck } from '@/api/team'
  import {userall} from '@/api/team'

  export default {
    name: "TeamRoleModal",
    data () {
      return {
        title:"操作",
        visible: false,
        teamDisabled: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          teamRolename:{
            rules: [
              { required: true, message: '请输入团队角色名称!' },
              { min: 0, max: 126, message: '长度在 2 到 30 个字符', trigger: 'blur' }
            ]}
        },
      }
    },
    created () {
    },
    methods: {

      add () {
        this.edit({});
      },
      edit (record) {
        /*      let that = this;*/
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        let that=this
        // that.model = Object.assign({}, this.model);
        that.$nextTick(() => {
          that.form.setFieldsValue(pick(this.model,'teamRolename'))
        });

      },

      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let avatar = that.model.avatar;
            let formData = Object.assign(this.model, values);
            //formData.avatar = avatar;
            let obj;
            console.log(formData)
            if(!this.model.id){
              obj=addTeamrole(formData);
            }else{
              obj=editTeamrole(formData);
            }
            obj.then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
      /*    validateSpecialtyCode(rule, value, callback){
       /!*     if(/[\u4E00-\u9FA5]/g.test(value)){
              callback("专业类别编码不可输入汉字!");
            }else{
              var params = {
                tableName: "sys_specialty",
                fieldName: "specialty_code",
                fieldVal: value,
                dataId: this.model.id,
              };*!/
              duplicateCheck(params).then((res)=>{
                if(res.success){
                  callback();
                }else{
                  callback(res.message);
                }
              });
            }
          }*/

    }
  }
</script>

<style scoped>

</style>